package ru.aslanov.schedule.client.ds;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.types.FieldType;
import ru.aslanov.schedule.client.ScheduleUser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 19, 2010 12:11:13 PM
 *
 * @author Sergey Aslanov
 */
public class UserDS extends ChildDS {
    private static Map<String, DataSource> instances = new HashMap<String, DataSource>();

    public static DataSource getInstance(ScheduleUser scheduleUser) {
        DataSource dataSource = instances.get(scheduleUser.getScheduleKey());
        if (dataSource == null) {
            dataSource = new UserDS(scheduleUser.getScheduleKey(), scheduleUser);
            instances.put(scheduleUser.getScheduleKey(), dataSource);
        }
        return dataSource;
    }

    private UserDS(String scheduleKey, InputLangProvider inputLangProvider) {
        super("User", scheduleKey, "schedule", inputLangProvider);

        DataSourceField email = new DataSourceField("email", FieldType.TEXT, cnt.emailField());
        email.setRequired(true);

        DataSourceField isAdmin = new DataSourceField("isAdmin", FieldType.BOOLEAN, cnt.isAdminField());

        setFields(encodedKey, email, isAdmin);
    }
}
